//
//  AppDelegate.m
//  WeiBo
//
//  Created by student on 16/4/21.
//  Copyright © 2016年 superKick. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "MessageViewController.h"
#import "MeViewController.h"
#import "HomeViewController.h"
#import "DiscoverViewController.h"
@interface AppDelegate ()

@property (nonatomic,strong) UITabBarController *tabBarController;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//    ViewController *vc = [[ViewController alloc] init];
//    self.window.rootViewController = vc;
    
    
    self.tabBarController  =[[UITabBarController alloc] init];
    self.tabBarController.tabBar.tintColor = [UIColor orangeColor];
    [self addChildViewController:[[HomeViewController alloc]init] imageName:@"tabbar_home" title:@"首页"];
    
    [self addChildViewController:[[MessageViewController alloc]init] imageName:@"tabbar_message_center" title:@"消息"];
    [self addChildViewController:[[UIViewController alloc] init] imageName:@"" title:@""];
    [self addChildViewController:[[DiscoverViewController alloc]init] imageName:@"tabbar_discover" title:@"发现"];
    [self addChildViewController:[[MeViewController alloc]init] imageName:@"tabbar_profile" title:@"我"];
    self.window.rootViewController = self.tabBarController;
    
    [self addcomposeBtn];
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)addcomposeBtn
{
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_hightlighted"] forState:UIControlStateHighlighted];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_hightlighted"] forState:UIControlStateHighlighted];
    [self.tabBarController.tabBar addSubview:btn];
    int width = [UIScreen mainScreen].bounds.size.width / 5;
    btn.frame = CGRectMake(width*2, 0, width, 49);
    [btn addTarget:self action:@selector(composeBtnPressed) forControlEvents:UIControlEventTouchUpInside];

}

- (void) composeBtnPressed
{
    
}

- (void) addChildViewController:(UIViewController *)vc imageName:(NSString *)imageName title:(NSString *)title
{
    
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]];
    vc.tabBarItem.title = title;
    vc.title = title;
    
    UINavigationController *Navi = [[UINavigationController alloc] initWithRootViewController:vc];
    [self.tabBarController addChildViewController:Navi];
}
@end